import time
from django.utils.deprecation import MiddlewareMixin


class RequestTimerMiddleware(MiddlewareMixin):
    def process_request(self, request):
        request._start_time = time.time()

    def process_response(self, request, response):
        duration = time.time() - getattr(request, '_start_time', time.time())
        print(f"{request.path} took {duration:.2f} seconds")
        return response